﻿myApp.controller("propertyDirectoryController", function ($scope, $http, $modal, $routeParams, authService, ngTableParams, $filter, $location, $window, $rootScope) {
    document.title = "Penang Realty 世界地產 Our Marketing Project";
    $scope.$emit('newPageLoaded', { 'title': 'Penang Realty 世界地產 Our Marketing Project', 'description': 'Enjoy great discount. Check our marketing projects now.' });
    function pageInit() {
        $scope.loader = { loading: true };
        var url = 'api/PropertyDirectory/GetPropertyDirectory';
        $http.get(url).success(function (data) {
            console.log(data);
            $scope.data.Property = data;

            $scope.tableParams = new ngTableParams({
                page: 1,            // show first page
                count: 25,           // count per page
                filter: {
                    ProjectName: ''       // initial filter
                }

            }, {
                total: $scope.data.Property.length, // length of data
                getData: function ($defer, params) {

                    var orderedProperty = params.filter() ? $filter('filter')($scope.data.Property, params.filter()) : $scope.data.Property;
                    // use build-in angular filter
                    orderedProperty = params.sorting() ? $filter('orderBy')(orderedProperty, params.orderBy()) : orderedProperty;
                    params.total(orderedProperty.length); // set total for recalc pagination
                    $defer.resolve(orderedProperty.slice((params.page() - 1) * params.count(), params.page() * params.count()));
                    $scope.loader = { loading: false };
                }
            })


        })
        
    }
    $scope.go = function (key, value) {
        //property.ProjectId,property
        console.log(key);
        console.log(value);
        value['Project'] = $scope.property;
        var jsonObj = JSON.stringify(value);
        sessionStorage.setItem(key, jsonObj);
    }
    pageInit();



})
